package panel;

import interfaces.FileListViewer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileSystemView;


public class TabularView extends FileListViewer {

	private static final long serialVersionUID = 1L;
	
	
    Object[][] data = null;
    
    final JTable table;
    
	@SuppressWarnings("serial")
	public TabularView(String path) {
		super(path);
		setBackground(Color.white);
		
		
		data = new Object[list.length][];
		FileSystemView view = FileSystemView.getFileSystemView(); 
		
		for(int i = 0; i < list.length; i++){
			data[i] = new Object[]{ view.getSystemIcon(list[i]) ,list[i].getName(), "" };
		}
		
		TableModel model = new TableModel(data);
		
		table = new Snowtable(model);
		
		
		table.getTableHeader().setReorderingAllowed(false);
		table.setAutoCreateRowSorter(true);
		
		table.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent me) {
				if(me.getClickCount() == 2){
					int index = table.getSelectedRow();
					run(list[index]);
				}
				
			}

			public void mouseEntered(MouseEvent arg0) {}

			public void mouseExited(MouseEvent arg0) {}

			public void mousePressed(MouseEvent arg0) {}

			public void mouseReleased(MouseEvent arg0) {}
			
		});
		
        table.setPreferredScrollableViewportSize(new Dimension(1000, 500));
        table.setFillsViewportHeight(true);
		table.getTableHeader().setReorderingAllowed(false);
		
        
        
        JScrollPane scrollPane = new JScrollPane(table);
        scrollPane.setBorder(BorderFactory.createEmptyBorder());

        //Add the scroll pane to this panel.
        add(scrollPane);
		
	}



}
